<?php
Core::getInstance()->sys_load_class('Model',false);
class DatabaseTool extends Model{
	public function import($content){
		$sqls = $this->fnParseSql($content);
		foreach($sqls as $sql){
			if(!empty($sql)) $this->query($sql); // 执行sql语句
		}
	}
	// 组合成可执行的语句 
	public function fnParseSql($sql=''){
		$sql = str_replace("\r","\n",$sql);
		$ret = array();
		$aSql = explode(";\n",trim($sql));
		unset($sql);
		$num = 0;
		foreach($aSql as $sql){
			$ret[$num]='';
			$queries = explode("\n",$sql);
			$queries = array_filter($queries);
			foreach($queries as $query){
				$str1 = substr($query,0,1);
				if($str1!=='#' && $str1!=='-' && $str1!='/' && $str1!=='\\' ) $ret[$num].=$query;
			}
			$num++;
		}
		return $ret;
	}

}
